package com.zz.kt.order.api;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zz.kt.model.order.OrderInfo;
import com.zz.kt.model.vod.Course;
import com.zz.kt.order.service.OrderInfoService;
import com.zz.kt.result.Result;
import com.zz.kt.vo.order.OrderFormVo;
import com.zz.kt.vo.order.OrderInfoQueryVo;
import com.zz.kt.vo.order.OrderInfoVo;
import com.zz.kt.vo.vod.CourseQueryVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoApiController {

    @Autowired
    private OrderInfoService orderInfoService;

    //生成订单方法
    @ApiOperation("新增点播课程订单")
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody OrderFormVo orderFormVo){
        Long orderId = orderInfoService.submitOrder(orderFormVo);
        return Result.ok(orderId);
    }

    @ApiOperation(value = "获取订单信息")
    @GetMapping("/getInfo/{id}")
    public Result getInfo(@PathVariable Long id) {
        OrderInfoVo orderInfoVo = orderInfoService.getOrderInfoVoById(id);
        return Result.ok(orderInfoVo);
    }

    //查询是否购买课程
    @ApiOperation(value = "查询是否购买课程")
    @GetMapping("selectStatus/{userId}/{courseId}")
    public Boolean selectStatus(@PathVariable Long userId,@PathVariable Long courseId) {
        Boolean orderInfoVo = orderInfoService.selectStatus(userId,courseId);
        return orderInfoVo;
    }

    //订单列表(根据用户id
    @GetMapping("/findListByUserId")
    public Result findListByUserId(){
        List orderList = orderInfoService.selectOrderInfoPageByUserId();
        return Result.ok(orderList);
    }

    //根据userId查询已购的课程列表
    @GetMapping("findCourseListByUserId")
    public Result findCourseListByUserId(){
        List courseList = orderInfoService.selectCourseInfoByUserId();
        return Result.ok(courseList);
    }
}
